#ifndef __TABLE_H
#define __TABLE_H
#include <stdint.h>
#include <stddef.h>


#define TABLE_REFRESH_SLEEP_TIME    50000


typedef enum
{
    TABLE_MSGVAL_NONE           = 0,    /* 不需要刷新 */
    TABLE_MSGVAL_FPGA           = 1,    /* FPGA数据刷新时 */
    TABLE_MSGVAL_TEMP           = 2,    /* 温度数据刷新时 */
    TABLE_MSGVAL_ELEC_QUTT      = 3,    /* 电量数据刷新时 */
    TABLE_MSGVAL_MODE           = 4,    /* 模式数据刷新时 */
    TABLE_MSGVAL_TIME           = 5,    /* 定时刷新 */
} tableMsgVal_t;


typedef enum
{
    TABLE_ERR_NONE       = 0,
    TABLE_ERR_INIT       = 1,
    TABLE_ERR_SEARCH     = 2,
    TABLE_ERR_NO_SUPPORT = 3,
} tableErr_t;


typedef enum
{
    TEA_RD   = 0x1,
    TEA_WR   = 0x2,
    TEA_RDWR = (TEA_RD | TEA_WR),
} tableEntryAttr_t;


typedef struct
{
    uint32_t idx;
    tableEntryAttr_t attr;
    uint16_t data;
    tableMsgVal_t msgVal;
    void *pExtra;
} tableEntry_t;


typedef tableEntry_t table_t;


#define TABLE_ENTRY_INIT(_idx, _attr, _msgVal, ...) \
{ \
    .idx    = (_idx), \
    .attr   = (_attr), \
    .msgVal = (_msgVal), \
    .pExtra = (NULL), \
}


#endif
